<template>
  <a-layout>
    <a-layout-content style="height: calc(100vh - 88px); padding: 2px">
      <VxeBasicTable ref="TableRef" v-bind="options">
        <template #toolbar_buttons>
          <ToolBtn
            :filter-call="handleOpenFilter"
            :create-call="handleDelete"
            :show-export="false"
            :show-import="false"
            :show-delete="false"
            :show-filter="false"
          />
        </template>
        <template #action="{ row }">
          <Action :record="row" @edit="handleOpenView" />
        </template>
      </VxeBasicTable>
    </a-layout-content>
    <DifflogDrawer v-model:visible="showLogView" :data="currentData" />
    <TableFilter
      ref="FilterRef"
      @done="reload"
      v-model:visible="ifSHowFilter"
      :filter-cols="Columns"
    />
  </a-layout>
</template>

<script lang="ts" setup>
  import { ref } from 'vue';
  import { message } from 'ant-design-vue/es';
  import { messageLoading } from 'ele-admin-pro/es';
  import { getDiffLogPageList, clearDiffLog } from '@/api/system/log';
  import { useConfig } from './config';
  import DifflogDrawer from './components/DifflogDrawer.vue';

  const {
    TableRef,
    FilterRef,
    Columns,
    TableFilter,
    ToolBtn,
    Action,
    options
  } = useConfig(getDiffLogPageList);

  const currentData = ref();
  const ifSHowFilter = ref(false);
  const showLogView = ref(false);

  /* 刷新表格 */
  const reload = () => {
    TableRef.value?.commitProxy('query');
  };
  const handleOpenView = (row) => {
    currentData.value = row;
    showLogView.value = true;
  };
  const handleOpenFilter = () => {
    ifSHowFilter.value = true;
  };

  /* 删除 */
  const handleDelete = () => {
    const hide = messageLoading('请求中..', 0);
    clearDiffLog()
      .then((msg) => {
        hide();
        message.success(msg);
        reload();
      })
      .catch((e) => {
        hide();
        message.error(e.message);
      });
  };
</script>

<script lang="ts">
  export default {
    name: 'ExlogManagement'
  };
</script>
